﻿using System;
using System.Windows.Forms;
using IceCS.GoodsSale.BLL;

namespace IceCS.GoodsSale.Winform
{
    public partial class FrmRestoreData : Form
    {
        public FrmRestoreData()
        {
            InitializeComponent();
        }

        string restorePath = "";

        private void btnRestorePath_Click(object sender, EventArgs e)
        {
            odlgRestore.FilterIndex = 0;
            odlgRestore.FileName = "";
            odlgRestore.Filter = "Bak Files (*.bak)|*.bak|All Files (*.*)|*.*";
            if (odlgRestore.ShowDialog() == DialogResult.OK)
            {
                txtRestore.Text = odlgRestore.FileName.ToString();
                txtRestore.ReadOnly = true;
            }
            restorePath = txtRestore.Text.Trim();
        }

        private void btnRestore_Click(object sender, EventArgs e)
        {
            try
            {
                if (restorePath == "")
                {
                    MessageBox.Show("请先选择数据库恢复路径", "提示");
                    return;
                }
                PublicMethodsManager publicMethodsManager = new PublicMethodsManager();
                if (publicMethodsManager.RestoreDB(restorePath))
                {
                    MessageBox.Show("数据库恢复成功", "提示");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("数据库恢复失败", "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
